<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>二手市场</title>
</head>
<body>
	<?php require_once ".\system\dbConn.php";
    require_once('head.php'); 

     $sql="select * from goods where ischeck=0";
		//若果点击了搜索提交按钮，sql语句要改变
		
		if (isset($_GET["key"])) {
			$key=trim($_GET["key"]);
			$sql="select * from goods where name like '%{$key}%' and ischeck=0";
		}

		$result=mysqli_query($link,$sql);
//结果集
		$num=mysqli_num_rows($result);
		$rowprepage=9;//每页条数
		if (!isset($_GET["page"])) {
			$page=1;
		}else{
			$page=$_GET["page"];
		}
		if ($num%$rowprepage==0) {
			$totalpages=$num/$rowprepage;//总共多少页
		}else{
			$totalpages=ceil($num/$rowprepage);
		}
		$start=($page-1)*$rowprepage;//每页起始编号
		
		$sql0 = "select * from goods where ischeck=0 limit $start,$rowprepage ";
		$result0=mysqli_query($link,$sql0);
//每页结果集

		if ($num==0) {
			echo "没有找到符合条件的任务";
			exit;
		}
    ?>
    <div style="width: 75%;margin:20px auto;background-color:#F8F8FF;opacity:0.9;">
	<div style="width: 75%;margin:20px auto;">
		<div class="col-md-12">
		<div class="row">
		<div class="col-md-11">
				<button type="button" class="btn btn-dark"data-toggle="modal" data-target="#demand" style="float:right;margin-right:10px;margin-top: 40px;">发布商品</button>
		</div>
		</div>
		<div class="row" style="margin-top:20px;margin-bottom:10px;">
    		<div class="container">
		    <div class="row row-offcanvas row-offcanvas-right">
		        <div class="col-xs-12 col-sm-12">
		            <div class="row">
		                <div class="col-xs-12 col-lg-12 mlist">
		                    <ul class="list-inline row text-center">
		                        <?php 
		                            while ($row=mysqli_fetch_assoc($result0)) {
		                         ?>    
		                                <div class="row" style="margin-left: 30px;background-color:#ffffff;padding:10px;margin-top: 20px">
										  <div class="col-sm-2 col-md-12">
										    <div class="thumbnail">
										       <img src="./images/<?php echo $row["pic"];?>" class="img-responsive" alt="Responsive image"  width="140" height="180" title="介绍：<?php echo $row["detial"]; ?>">

										      <div class="caption" style="margin-top: 10px">
										        <h6><a href="#"><?php echo $row["gname"]; ?></a></h6>
										        <p style="font-size: 10px"><?php echo $row["time"]; ?>&nbsp&nbsp<?php echo "￥".$row["price"]."元 "; ?></p>
										        <p style="font-size: 13px"><?php echo $row["uploaduser"]; ?>:&nbsp&nbsp<?php echo $row["phone"]; ?></p>
										         <p style="font-size: 13px;width: 200px">详情:&nbsp&nbsp<?php echo $row["detial"]; ?></p>
										      </div>
										    </div>
										  </div>
										</div>
		                        <?php 
		                            }
		                         ?>
		                    </ul>
		                </div>
		                <!--/.col-xs-6.col-lg-4-->
		            </div>
		            <!--/row-->
		        </div>
		        <!--/.col-xs-12.col-sm-9-->
		</div>
		</div>
		<nav style="text-align: center;margin-left: 350px">
			<ul class="pagination"  >
				<?php
				// echo "<li>共有".$num."条记录,共分了".$totalpages."页"."&nbsp;</li>";
				echo "<li class=\"page-item\"><a class=\"page-link\" href=\"?page=1\">首页</a></li>";
				if ($page > 1) {
					echo "<li class=\"page-item\"><a class=\"page-link\" href=\"?page=".($page-1)."\">上页</a></li>";
				}
				
				//第i页的超链接
				for ($i=1; $i<=$totalpages; $i++){ 
					echo "<li class=\"page-item\"><a class=\"page-link\" href=\"?page=$i\">$i</a></li>";
				}
				//尾页下一页
				if ($page < $totalpages) {
					echo "<li class=\"page-item\"><a class=\"page-link\" href=\"?page=".($page+1)."\">下页</a></li>";
				}
				echo "<li class=\"page-item\"><a class=\"page-link\" href=\"?page=$totalpages\">尾页</a></li>";
				?>
			</ul>
		</nav>
		</div>
		</div>	
	</div>
</div>

	<div class="modal fade" id="demand" tabindex="-1" role="dialog" aria-labelledby="demand" aria-hidden="true">
		<div class="modal-dialog modal-dialog-centered" role="document">
		  <div class="modal-content">
		    <div class="modal-header">
			  <h5 class="modal-title" id="demand">商品发布</h5>
		      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>		        
		    </div>
		    <div class="modal-body">
			<form class="form-horizontal" action="doMarket.php" method="post" enctype="multipart/form-data">
				  <div class="form-group row">
				    <label for="inputName" class="col-md-2 col-form-label">商品名:</label>
				    <div class="col-md-10">
				      <input id="damandName" type="text" class="form-control" name="name" placeholder="商品名">
				    </div>
				  </div>

				  <div class="form-group row">
		            <label for="type" class="col-md-2 col-form-label">类&nbsp&nbsp&nbsp型:</label>
		            <div class="col-md-10">
		            	<select id="selectType" class="form-control" name="type">
				     		<option value="0">生活用品</option>
		             		<option value="1">电子产品</option>
		             		<option value="2">学习资料</option>
		             		<option value="3">其他</option>
						</select>
		            </div>
		          </div>

				   <div class="form-group row">
			            <label for="inputPic" class="col-md-2 control-label">图&nbsp&nbsp&nbsp片：</label>
			            <div class="col-md-10">
			              <input type="file" name="pic"  id="inputPic">
			            </div>
          			</div>

				   <div class="form-group row">
				    <label for="inputM" class="col-md-2 col-form-label">价&nbsp&nbsp&nbsp格：</label>
				    <div class="col-md-10">
				      <input type="text" class="form-control" id="inputM" name="money" placeholder="价格">
				    </div>
				  </div>

				  <div class="form-group row">
				    <label for="inputM" class="col-md-2 col-form-label">电&nbsp&nbsp&nbsp话：</label>
				    <div class="col-md-10">
				      <input type="text" class="form-control" id="inputP" name="phone" placeholder="联系方式">
				    </div>
				  </div>

				  <div class="form-group row">
		            <label for="inputdetails" class="col-md-2 col-form-label">详&nbsp&nbsp&nbsp情:</label>
		            <div class="col-md-10">
		            	<textarea name="details" id="inputdetails" cols="50" rows="5" placeholder="商品介绍"></textarea>
	              	</div>
				  </div>
				  <div class="modal-footer">
				  	<button id="marketBtn"  class="btn btn-primary btn-lg active " >提交</button>
				  </div>
				</form>	
		    </div>
		  </div>
		</div>
	</div>  
</body>
<style >
body{
	 	 background:#ffffff url(./assets/background.png);
	 	 background-size:100%;
	 }
</style>
</html>